package com.longrise.android.byjk.plugins.tabthird.invoice;

import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/20.
 * 开票历史adapter
 */

class BillHistoryAdapter extends BaseQuickAdapter<EntityBean, BaseViewHolder> {

    private OnItemClickListener mListener;
    private List<EntityBean> mListBeans = new ArrayList<>();

    public BillHistoryAdapter() {
        super(R.layout.item_bill_history);
    }

    public void refreshData(EntityBean[] beans) {
        mListBeans.clear();
        for (EntityBean bean : beans) {
            mListBeans.add(bean);
        }
        setNewData(mListBeans);
    }

    @Override
    protected void convert(final BaseViewHolder helper, EntityBean item) {

        final int position = helper.getLayoutPosition();
        final View convertView = helper.getConvertView();
        EntityBean typeBean2 = mListBeans.get(position);
        TextView tv_bill_name = (TextView) convertView.findViewById(R.id.tv_bill_name);
        TextView tv_bill_time = (TextView) convertView.findViewById(R.id.tv_bill_time);
        TextView tv_bill_price = (TextView) convertView.findViewById(R.id.tv_bill_price);
        TextView tv_bill_state = (TextView) convertView.findViewById(R.id.tv_bill_state);
        if (typeBean2 != null) {
            String invstate = typeBean2.getString("invstate");
            tv_bill_name.setText(typeBean2.getString("customername"));
            tv_bill_time.setText(typeBean2.getString("createdate"));
            tv_bill_price.setText("¥" + typeBean2.getString("amt"));
            if(invstate.equals("1")){
                tv_bill_state.setText("办理中");
               tv_bill_state.setTextColor(Color.parseColor("#FFFBA140"));
            }else if(invstate.equals("2")){
                tv_bill_state.setText("已办理");
                tv_bill_state.setTextColor(Color.parseColor("#FFD8D8D8"));
            }
        }

//        convertView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (mListener != null) {
//                    mListener.onItemClick(convertView,position);
//                }
//            }
//        });

        //让最后的item 分割线不显示
        int layoutPosition = helper.getLayoutPosition();
        if (layoutPosition == mListBeans.size()-1) {
            helper.getView(R.id.line_bill_history).setVisibility(View.GONE);
        }else{
            helper.getView(R.id.line_bill_history).setVisibility(View.VISIBLE);
        }

    }



}
